home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / financ1a / moneymat.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1999-10-13  |  40.6 KB  |  1,107 lines

  1. VERSION 5.00
  2. Object = "{3B7C8863-D78F-101B-B9B5-04021C009402}#1.2#0"; "RICHTX32.OCX"
  3. Begin VB.Form frmMoneyMath 
  4.    BorderStyle     =   1  'Fixed Single
  5.    Caption         =   "Financial Reckoner"
  6.    ClientHeight    =   6360
  7.    ClientLeft      =   45
  8.    ClientTop       =   330
  9.    ClientWidth     =   7740
  10.    ForeColor       =   &H00C0C0C0&
  11.    Icon            =   "MoneyMath.frx":0000
  12.    LinkTopic       =   "Form2"
  13.    LockControls    =   -1  'True
  14.    MaxButton       =   0   'False
  15.    MinButton       =   0   'False
  16.    ScaleHeight     =   6360
  17.    ScaleWidth      =   7740
  18.    Begin VB.Frame Frame2 
  19.       Caption         =   "Answer"
  20.       BeginProperty Font 
  21.          Name            =   "MS Sans Serif"
  22.          Size            =   8.25
  23.          Charset         =   0
  24.          Weight          =   700
  25.          Underline       =   0   'False
  26.          Italic          =   0   'False
  27.          Strikethrough   =   0   'False
  28.       EndProperty
  29.       Height          =   2385
  30.       Left            =   4020
  31.       TabIndex        =   11
  32.       Top             =   3840
  33.       Width           =   3525
  34.       Begin VB.PictureBox Picture2 
  35.          Height          =   405
  36.          Left            =   1080
  37.          ScaleHeight     =   345
  38.          ScaleWidth      =   375
  39.          TabIndex        =   18
  40.          Top             =   210
  41.          Width           =   435
  42.          Begin VB.CommandButton cmdClear 
  43.             BeginProperty Font 
  44.                Name            =   "MS Sans Serif"
  45.                Size            =   8.25
  46.                Charset         =   0
  47.                Weight          =   700
  48.                Underline       =   0   'False
  49.                Italic          =   0   'False
  50.                Strikethrough   =   0   'False
  51.             EndProperty
  52.             Height          =   345
  53.             Left            =   -30
  54.             Picture         =   "MoneyMath.frx":030A
  55.             Style           =   1  'Graphical
  56.             TabIndex        =   19
  57.             TabStop         =   0   'False
  58.             ToolTipText     =   "Clear"
  59.             Top             =   0
  60.             Width           =   405
  61.          End
  62.       End
  63.       Begin VB.PictureBox Picture1 
  64.          Height          =   405
  65.          Left            =   420
  66.          ScaleHeight     =   345
  67.          ScaleWidth      =   375
  68.          TabIndex        =   14
  69.          Top             =   210
  70.          Width           =   435
  71.          Begin VB.CommandButton cmdAnswer 
  72.             BeginProperty Font 
  73.                Name            =   "MS Sans Serif"
  74.                Size            =   8.25
  75.                Charset         =   0
  76.                Weight          =   700
  77.                Underline       =   0   'False
  78.                Italic          =   0   'False
  79.                Strikethrough   =   0   'False
  80.             EndProperty
  81.             Height          =   345
  82.             Left            =   -30
  83.             Picture         =   "MoneyMath.frx":035F
  84.             Style           =   1  'Graphical
  85.             TabIndex        =   15
  86.             TabStop         =   0   'False
  87.             ToolTipText     =   "Compute answer"
  88.             Top             =   0
  89.             Width           =   405
  90.          End
  91.       End
  92.       Begin VB.TextBox txtAnswer 
  93.          Alignment       =   1  'Right Justify
  94.          BackColor       =   &H80000018&
  95.          BeginProperty DataFormat 
  96.             Type            =   1
  97.             Format          =   """$""#,##0.00"
  98.             HaveTrueFalseNull=   0
  99.             FirstDayOfWeek  =   0
  100.             FirstWeekOfYear =   0
  101.             LCID            =   1033
  102.             SubFormatType   =   2
  103.          EndProperty
  104.          BeginProperty Font 
  105.             Name            =   "MS Sans Serif"
  106.             Size            =   8.25
  107.             Charset         =   0
  108.             Weight          =   700
  109.             Underline       =   0   'False
  110.             Italic          =   0   'False
  111.             Strikethrough   =   0   'False
  112.          EndProperty
  113.          Height          =   345
  114.          Left            =   2220
  115.          Locked          =   -1  'True
  116.          TabIndex        =   12
  117.          TabStop         =   0   'False
  118.          Text            =   "0"
  119.          Top             =   1950
  120.          Width           =   1155
  121.       End
  122.       Begin VB.Label lblAnswerNote 
  123.          Caption         =   "lblAnswerNote"
  124.          BeginProperty Font 
  125.             Name            =   "MS Sans Serif"
  126.             Size            =   8.25
  127.             Charset         =   0
  128.             Weight          =   700
  129.             Underline       =   0   'False
  130.             Italic          =   0   'False
  131.             Strikethrough   =   0   'False
  132.          EndProperty
  133.          Height          =   675
  134.          Left            =   90
  135.          TabIndex        =   20
  136.          Top             =   750
  137.          Width           =   3285
  138.       End
  139.       Begin VB.Label lblAnswer 
  140.          Caption         =   "lblAnswer"
  141.          BeginProperty Font 
  142.             Name            =   "MS Sans Serif"
  143.             Size            =   8.25
  144.             Charset         =   0
  145.             Weight          =   700
  146.             Underline       =   0   'False
  147.             Italic          =   0   'False
  148.             Strikethrough   =   0   'False
  149.          EndProperty
  150.          Height          =   405
  151.          Left            =   90
  152.          TabIndex        =   13
  153.          Top             =   1530
  154.          Width           =   3285
  155.       End
  156.    End
  157.    Begin VB.Frame Frame1 
  158.       Caption         =   "Actual data"
  159.       BeginProperty Font 
  160.          Name            =   "MS Sans Serif"
  161.          Size            =   8.25
  162.          Charset         =   0
  163.          Weight          =   700
  164.          Underline       =   0   'False
  165.          Italic          =   0   'False
  166.          Strikethrough   =   0   'False
  167.       EndProperty
  168.       Height          =   2385
  169.       Left            =   180
  170.       TabIndex        =   7
  171.       Top             =   3840
  172.       Width           =   3615
  173.       Begin VB.TextBox Text4 
  174.          Alignment       =   1  'Right Justify
  175.          BackColor       =   &H80000018&
  176.          BeginProperty DataFormat 
  177.             Type            =   1
  178.             Format          =   """$""#,##0.00"
  179.             HaveTrueFalseNull=   0
  180.             FirstDayOfWeek  =   0
  181.             FirstWeekOfYear =   0
  182.             LCID            =   1033
  183.             SubFormatType   =   2
  184.          EndProperty
  185.          Height          =   345
  186.          Left            =   2550
  187.          TabIndex        =   3
  188.          Text            =   "0"
  189.          Top             =   1830
  190.          Width           =   825
  191.       End
  192.       Begin VB.TextBox Text3 
  193.          Alignment       =   1  'Right Justify
  194.          BackColor       =   &H80000018&
  195.          BeginProperty DataFormat 
  196.             Type            =   1
  197.             Format          =   """$""#,##0.00"
  198.             HaveTrueFalseNull=   0
  199.             FirstDayOfWeek  =   0
  200.             FirstWeekOfYear =   0
  201.             LCID            =   1033
  202.             SubFormatType   =   2
  203.          EndProperty
  204.          Height          =   345
  205.          Left            =   2550
  206.          TabIndex        =   2
  207.          Text            =   "0"
  208.          Top             =   1350
  209.          Width           =   825
  210.       End
  211.       Begin VB.TextBox Text1 
  212.          Alignment       =   1  'Right Justify
  213.          BackColor       =   &H80000018&
  214.          BeginProperty DataFormat 
  215.             Type            =   1
  216.             Format          =   """$""#,##0.00"
  217.             HaveTrueFalseNull=   0
  218.             FirstDayOfWeek  =   0
  219.             FirstWeekOfYear =   0
  220.             LCID            =   1033
  221.             SubFormatType   =   2
  222.          EndProperty
  223.          Height          =   345
  224.          Left            =   2550
  225.          TabIndex        =   0
  226.          Text            =   "0"
  227.          Top             =   390
  228.          Width           =   825
  229.       End
  230.       Begin VB.TextBox Text2 
  231.          Alignment       =   1  'Right Justify
  232.          BackColor       =   &H80000018&
  233.          BeginProperty DataFormat 
  234.             Type            =   1
  235.             Format          =   """$""#,##0.00"
  236.             HaveTrueFalseNull=   0
  237.             FirstDayOfWeek  =   0
  238.             FirstWeekOfYear =   0
  239.             LCID            =   1033
  240.             SubFormatType   =   2
  241.          EndProperty
  242.          Height          =   345
  243.          Left            =   2550
  244.          TabIndex        =   1
  245.          Text            =   "0"
  246.          Top             =   870
  247.          Width           =   825
  248.       End
  249.       Begin VB.Label Label4 
  250.          Caption         =   "Label4"
  251.          Height          =   525
  252.          Left            =   210
  253.          TabIndex        =   17
  254.          Top             =   1830
  255.          Width           =   2175
  256.       End
  257.       Begin VB.Label Label3 
  258.          Caption         =   "Label3"
  259.          Height          =   435
  260.          Left            =   210
  261.          TabIndex        =   10
  262.          Top             =   1380
  263.          Width           =   2145
  264.       End
  265.       Begin VB.Label Label1 
  266.          Caption         =   "Label1"
  267.          Height          =   405
  268.          Left            =   210
  269.          TabIndex        =   9
  270.          Top             =   420
  271.          Width           =   2145
  272.       End
  273.       Begin VB.Label Label2 
  274.          Caption         =   "Label2"
  275.          Height          =   285
  276.          Left            =   210
  277.          TabIndex        =   8
  278.          Top             =   900
  279.          Width           =   2175
  280.       End
  281.    End
  282.    Begin VB.ComboBox cboRef 
  283.       BackColor       =   &H80000018&
  284.       BeginProperty Font 
  285.          Name            =   "MS Sans Serif"
  286.          Size            =   8.25
  287.          Charset         =   0
  288.          Weight          =   700
  289.          Underline       =   0   'False
  290.          Italic          =   0   'False
  291.          Strikethrough   =   0   'False
  292.       EndProperty
  293.       Height          =   315
  294.       Left            =   1920
  295.       Style           =   2  'Dropdown List
  296.       TabIndex        =   6
  297.       TabStop         =   0   'False
  298.       Top             =   3390
  299.       Width           =   795
  300.    End
  301.    Begin RichTextLib.RichTextBox rtbHypothesis 
  302.       Height          =   2535
  303.       Left            =   180
  304.       TabIndex        =   5
  305.       TabStop         =   0   'False
  306.       Top             =   720
  307.       Width           =   7395
  308.       _ExtentX        =   13044
  309.       _ExtentY        =   4471
  310.       _Version        =   393217
  311.       BackColor       =   -2147483624
  312.       HideSelection   =   0   'False
  313.       ReadOnly        =   -1  'True
  314.       ScrollBars      =   2
  315.       Appearance      =   0
  316.       TextRTF         =   $"MoneyMath.frx":03B6
  317.       BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
  318.          Name            =   "MS Sans Serif"
  319.          Size            =   8.25
  320.          Charset         =   0
  321.          Weight          =   700
  322.          Underline       =   0   'False
  323.          Italic          =   0   'False
  324.          Strikethrough   =   0   'False
  325.       EndProperty
  326.    End
  327.    Begin VB.Label lblScenario 
  328.       Caption         =   "Scenario"
  329.       BeginProperty Font 
  330.          Name            =   "MS Sans Serif"
  331.          Size            =   8.25
  332.          Charset         =   0
  333.          Weight          =   700
  334.          Underline       =   0   'False
  335.          Italic          =   0   'False
  336.          Strikethrough   =   0   'False
  337.       EndProperty
  338.       Height          =   255
  339.       Left            =   600
  340.       TabIndex        =   21
  341.       Top             =   390
  342.       Width           =   1035
  343.    End
  344.    Begin VB.Image Image1 
  345.       Height          =   480
  346.       Left            =   90
  347.       Picture         =   "MoneyMath.frx":048D
  348.       Top             =   30
  349.       Width           =   480
  350.    End
  351.    Begin VB.Label lblScenarioRef 
  352.       Caption         =   "Scenario Ref No."
  353.       BeginProperty Font 
  354.          Name            =   "MS Sans Serif"
  355.          Size            =   8.25
  356.          Charset         =   0
  357.          Weight          =   700
  358.          Underline       =   0   'False
  359.          Italic          =   0   'False
  360.          Strikethrough   =   0   'False
  361.       EndProperty
  362.       Height          =   255
  363.       Left            =   240
  364.       TabIndex        =   16
  365.       Top             =   3420
  366.       Width           =   1545
  367.    End
  368.    Begin VB.Label lblInstruction 
  369.       Caption         =   "To select, click on any part of a scenario text,  or select its  Ref No.,  then key in actual data."
  370.       ForeColor       =   &H00000080&
  371.       Height          =   315
  372.       Left            =   600
  373.       TabIndex        =   4
  374.       Top             =   90
  375.       Width           =   6675
  376.    End
  377. Attribute VB_Name = "frmMoneyMath"
  378. Attribute VB_GlobalNameSpace = False
  379. Attribute VB_Creatable = False
  380. Attribute VB_PredeclaredId = True
  381. Attribute VB_Exposed = False
  382. ' MoneyMath.frm
  383. ' By Herman Liu
  384. ' This code concerns money, nothing else but money.  It is written to serve as a
  385. ' ready Financial Reckoner of many facets. To avoid involving dry and complicated
  386. ' terms and jargons, it just presents different models of financial scenarios,
  387. ' e.g. interest rate, instalment amount, loan, investment, mortgage and annuity,
  388. ' etc. You choose any of them, key in your actual data and the computed answer
  389. ' is right there. An equally important utility is, it allows you to vary your
  390. ' data as many times and to any extent you may want, so as to test the sensitivity
  391. ' to the result of a change of certain variable(s), and/or to compare the impact
  392. ' between changes.  [Notes: 1. Readers who are not interested in money at all,
  393. ' nor in its mathematics, may still want to take a look as this program also shows
  394. ' some interesting programming techniques. 2. If old hands out there (e.g. ACMA/
  395. ' /FCMA, CA/CPA or mathematicians) spot any discrepancy in my formula and approach
  396. ' at the background in each situation, would you please let me know.]
  397. Option Explicit
  398. Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" _
  399.     (ByVal hwnd As Long, ByVal wMsg As Long, wParam As Long, lParam As Any) As Long
  400. Const EM_CHARFROMPOS& = &HD7
  401. Private Type POINTAPI
  402.     X As Long
  403.     y As Long
  404. End Type
  405. Dim testFlag1 As Boolean
  406. Dim testFlag2 As Boolean
  407. Dim SuspendFlag As Boolean
  408. Dim arrT(10) As String
  409. Private Sub Form_Load()
  410.     FillText
  411.     ClearAll
  412.     cboRef.Clear
  413.     Dim i
  414.     For i = 0 To UBound(arrT)
  415.         cboRef.AddItem i + 1
  416.     Next i
  417.     cboRef.ListIndex = 0
  418.     rtbHypothesis.MousePointer = vbIconPointer
  419.     SuspendFlag = False
  420. End Sub
  421. Private Sub FillText()
  422.    Dim t As String
  423.    t = "[1]   There had been a delay in settling your credit card statement of $1,500 last" & vbCrLf
  424.    t = t & "       month. This results in this month's statement showing an interest charge of" & vbCrLf
  425.    t = t & "       $40.  At what interest rate you are being charged?" & vbCrLf _
  426.       & vbCrLf
  427.    arrT(0) = t
  428.    t = "[2]   You wish to purchase at the price of $10,000 a paper which will mature in" & vbCrLf
  429.    t = t & "       30 days for $10,065. The bank manager tells you that the interest accrued" & vbCrLf
  430.    t = t & "       thereof is 8.0% p.a.  Can you verify what the bank manager says?" & vbCrLf & vbCrLf
  431.    arrT(1) = t
  432.    t = "[3]   How much to pay for the purchase of a Bill with a maturity amount of" & vbCrLf
  433.    t = t & "       $11,000 in 35 days, when the applicable interest rate is 7.0% p.a.?" & vbCrLf _
  434.        & vbCrLf
  435.    arrT(2) = t
  436.    t = "[4]   A car with a cash price of $25,000 is to be paid for by (1) a down payment" & vbCrLf
  437.    t = t & "       of $5,000 and (2) 60 monthly instalment payments of $450 each, starting" & vbCrLf
  438.    t = t & "       30 days thereafter .  What is the interest rate charged?" & vbCrLf _
  439.        & vbCrLf
  440.    arrT(3) = t
  441.    t = "[5]   A mortgage of $100,000 to be cleared by 144 equal monthly payments," & vbCrLf
  442.    t = t & "       starting after 30 days of signing.  At an average interest rate of 8% p.a.," & vbCrLf
  443.    t = t & "       what should be the amount of each payment?" & vbCrLf & vbCrLf
  444.    arrT(4) = t
  445.    t = "[6]   A mortgage of $150,000 to be cleared by 132 equal monthly payments of" & vbCrLf
  446.    t = t & "       $1,800 each, starting after 30 days of signing.  What is the interest rate" & vbCrLf
  447.    t = t & "       implied in the calculation?" & vbCrLf & vbCrLf
  448.    arrT(5) = t
  449.    t = "[7]   A mortgage of $130,000 to be cleared by 156 equal monthly payments of" & vbCrLf
  450.    t = t & "       $1,650 each.  You have the option, which must be exercised after the 24th" & vbCrLf
  451.    t = t & "       payment and before the last 24 payments, to discharge whatever the balance" & vbCrLf
  452.    t = t & "       of loan in full without incurring any penalty.  After 38 payments, you decide to" & vbCrLf
  453.    t = t & "       exercise the option: (A) What are the principal and interest amounts paid so" & vbCrLf
  454.    t = t & "       far and (B) How much do you have to pay for the remaining balance?" & vbCrLf & vbCrLf
  455.    arrT(6) = t
  456.    t = "[8]   What is the present worth of $10,000 due after 5 years, taking into account" & vbCrLf
  457.    t = t & "       of an average interest rate of 8.0% p.a. compounded semi-annually?" & vbCrLf _
  458.       & vbCrLf
  459.    arrT(7) = t
  460.    t = "[9]   You put $5,000 into an account at the beginning of every year for 5 years." & vbCrLf
  461.    t = t & "       How much would the account balance be at the end of 5 years if the" & vbCrLf
  462.    t = t & "       agreed interest rate is 6.0% p.a. compounded quarterly?" & vbCrLf _
  463.        & vbCrLf
  464.    arrT(8) = t
  465.    t = "[10]  You plan to have an annuity which will enable you to draw $10,000 every" & vbCrLf
  466.    t = t & "       year for 15 years, starting one year from now.  Given an interest rate of" & vbCrLf
  467.    t = t & "       6.0% p.a., what should be the amount of the annuity?" & vbCrLf & vbCrLf
  468.    arrT(9) = t
  469.    t = "[11]  An annuity which will enable you to draw an amount each year for 15 years," & vbCrLf
  470.    t = t & "       starting one year from now.  The amount of first year is $10,000 and each" & vbCrLf
  471.    t = t & "       subsequent year a 10% increase over the previous one.  At an interest of" & vbCrLf
  472.    t = t & "       6.0% p.a., what is the present worth of this annuity?" & vbCrLf
  473.    arrT(10) = t
  474.    rtbHypothesis.Text = arrT(0) & arrT(1) & arrT(2) & arrT(3) & arrT(4) & arrT(5) & arrT(6) & arrT(7) _
  475.       & arrT(8) & arrT(9) & arrT(10)
  476. End Sub
  477. Private Sub ClearAll()
  478.     Label1.Caption = ""
  479.     Label2.Caption = ""
  480.     Label3.Caption = ""
  481.     Label4.Caption = ""
  482.     Text1.Text = 0
  483.     Text2.Text = 0
  484.     Text3.Text = 0
  485.     Text4.Text = 0
  486.     Text1.Visible = False
  487.     Text2.Visible = False
  488.     Text3.Visible = False
  489.     Text4.Visible = False
  490.     lblAnswerNote.Caption = ""
  491.     lblAnswerNote.Visible = False
  492.     lblAnswer.Caption = ""
  493.     lblAnswer.Visible = False
  494.     txtAnswer.Text = 0
  495.     txtAnswer.Visible = False
  496. End Sub
  497. Private Sub rtbHypothesis_MouseUp(Button As Integer, Shift As Integer, X As Single, y As Single)
  498.     SuspendFlag = True
  499.     ClearAll
  500.     HighlightRef1 X, y
  501.     SuspendFlag = False
  502.     GetDataInput
  503.     Text1.SetFocus
  504. End Sub
  505. Private Sub Text1_KeyPress(KeyAscii As Integer)
  506.      FilterAmountKey KeyAscii
  507. End Sub
  508. Private Sub Text2_KeyPress(KeyAscii As Integer)
  509.      FilterAmountKey KeyAscii
  510. End Sub
  511. Private Sub Text3_KeyPress(KeyAscii As Integer)
  512.      FilterAmountKey KeyAscii
  513. End Sub
  514. Private Sub Text4_KeyPress(KeyAscii As Integer)
  515.      FilterAmountKey KeyAscii
  516. End Sub
  517. Private Sub txtAnswer_KeyPress(KeyAscii As Integer)
  518.      FilterAmountKey KeyAscii
  519. End Sub
  520. Private Sub HighlightRef1(X As Single, y As Single)
  521.     Dim pt As POINTAPI
  522.     Dim chrPos As Integer
  523.     Dim startPos As Integer
  524.     Dim ch As String
  525.     Dim txt As String
  526.     Dim n As String
  527.        ' Convert screen pos to pixels.
  528.     pt.X = X \ Screen.TwipsPerPixelX
  529.     pt.y = y \ Screen.TwipsPerPixelY
  530.     chrPos = SendMessage(rtbHypothesis.hwnd, EM_CHARFROMPOS, 0, pt)
  531.     If chrPos <= 0 Then
  532.         Exit Sub
  533.     End If
  534.     txt = rtbHypothesis.Text
  535.     If "]" <> Mid(txt, chrPos + 2, 1) Then
  536.          For startPos = chrPos To 1 Step -1
  537.              ch = Mid(txt, startPos, 1)
  538.              If ch = "[" Then
  539.                   Exit For
  540.              ElseIf ch = "?" Then
  541.                  rtbHypothesis.SelLength = 0
  542.                  Exit Sub
  543.              End If
  544.          Next startPos
  545.     Else
  546.          startPos = chrPos
  547.     End If
  548.        ' Ref is the char(s) after startPos
  549.     ch = Mid(txt, startPos + 2, 1)
  550.     If ch = "]" Then
  551.        n = Val(Mid(txt, startPos + 1, 1))
  552.     Else
  553.        n = Val(Mid(txt, startPos + 1, 2))
  554.     End If
  555.        ' Synchronize value in cboRef
  556.     cboRef.ListIndex = n - 1
  557.     rtbHypothesis.SelStart = startPos - 1
  558.     rtbHypothesis.SelLength = Len(Trim(arrT(Val(n - 1)))) - 1
  559. End Sub
  560. Private Sub HighlightRef2(inRef As String)
  561.     Dim startPos As Integer
  562.     Dim txt As String
  563.     txt = rtbHypothesis.Text
  564.     startPos = InStr(txt, "[" & inRef & "]")
  565.     If startPos = 0 Then
  566.          Exit Sub
  567.     End If
  568.     If startPos > 0 Then
  569.          rtbHypothesis.SelStart = startPos - 1
  570.     Else
  571.          rtbHypothesis.SelStart = startPos - 1
  572.     End If
  573.     rtbHypothesis.SelLength = Len(Trim(arrT(Val(inRef) - 1))) - 1
  574. End Sub
  575. Private Sub cboRef_Click()
  576.     If SuspendFlag Then
  577.         Exit Sub
  578.     End If
  579.     ClearAll
  580.     GetDataInput
  581.     HighlightRef2 cboRef.Text
  582. End Sub
  583. Private Sub GetDataInput()
  584.     Select Case cboRef.ListIndex
  585.         Case 0
  586.              Label1 = "Payment delayed: $"
  587.              Label2 = "Interest amount: $"
  588.              Text1.Visible = True
  589.              Text2.Visible = True
  590.              lblAnswer.Caption = "Effective interest rate at (% p.a.)"
  591.         Case 1
  592.              Label1 = "Price: $"
  593.              Label2 = "No of days"
  594.              Label3 = "Amount on maturity: $"
  595.              Text1.Visible = True
  596.              Text2.Visible = True
  597.              Text3.Visible = True
  598.                ' Invisible still; fix its value first
  599.              lblAnswer.Caption = "Ordinary interest rate (% p.a.)"
  600.         Case 2
  601.              Label1 = "Amount on maturity: $"
  602.              Label2 = "No. of days"
  603.              Label3 = "Interest at % p.a."
  604.              Text1.Visible = True
  605.              Text2.Visible = True
  606.              Text3.Visible = True
  607.              lblAnswer.Caption = "Purchase price should be ($)"
  608.         Case 3
  609.              Label1 = "Cash price less down pmt: $"
  610.              Label2 = "Total No. of pmt"
  611.              Label3 = "Amount of each pmt: $"
  612.              Text1.Visible = True
  613.              Text2.Visible = True
  614.              Text3.Visible = True
  615.              lblAnswer.Caption = "Interest rate (% p.a.)"
  616.         Case 4
  617.              Label1 = "Mortgage amount: $"
  618.              Label2 = "Total No. of pmt"
  619.              Label3 = "Interest at % p.a."
  620.              Text1.Visible = True
  621.              Text2.Visible = True
  622.              Text3.Visible = True
  623.              lblAnswer.Caption = "Each instalment is ($)"
  624.         Case 5
  625.              Label1 = "Mortgage amount: $"
  626.              Label2 = "Total No. of pmt"
  627.              Label3 = "Monthly pmt: $"
  628.              Text1.Visible = True
  629.              Text2.Visible = True
  630.              Text3.Visible = True
  631.              lblAnswer.Caption = "Interest rate implied (% p.a)"
  632.         Case 6
  633.              Label1 = "Mortgage amount: $"
  634.              Label2 = "Total No. of pmt"
  635.              Label3 = "Amount each pmt: $"
  636.              Label4 = "Option after No. of pmt"
  637.              Text1.Visible = True
  638.              Text2.Visible = True
  639.              Text3.Visible = True
  640.              Text4.Visible = True
  641.              lblAnswer.Caption = "B: Ignoring diff due to rounding, balance to be" & _
  642.                     " paid is ($):"
  643.         Case 7
  644.              Label1 = "Amount"
  645.              Label2 = "Due No. of years from now"
  646.              Label3 = "Interest % p.a."
  647.              Label4 = "Interest computed: time(s) in year"
  648.              Text4.Text = 2                     ' Give default
  649.              Text1.Visible = True
  650.              Text2.Visible = True
  651.              Text3.Visible = True
  652.              Text4.Visible = True
  653.              lblAnswer.Caption = "Present worth is ($)"
  654.         Case 8
  655.              Label1 = "Yearly deposit: $"
  656.              Label2 = "No. of years"
  657.              Label3 = "Interest at % p.a."
  658.              Label4 = "Interest computed: time(s) in year"
  659.              Text4.Text = 4                     ' Give default
  660.              Text1.Visible = True
  661.              Text2.Visible = True
  662.              Text3.Visible = True
  663.              Text4.Visible = True
  664.              lblAnswer.Caption = "Account balance should be ($)"
  665.         Case 9
  666.              Label1 = "Yearly draw: $"
  667.              Label2 = "No. of years"
  668.              Label3 = "Interest % p.a."
  669.              Text1.Visible = True
  670.              Text2.Visible = True
  671.              Text3.Visible = True
  672.              lblAnswer.Caption = "Value of annuity now is ($)"
  673.         Case 10
  674.              Label1 = "Amount of first draw: $"
  675.              Label2 = "Increment over prev year: %"
  676.              Label3 = "No. of years"
  677.              Label4 = "Interest % p.a."
  678.              Text1.Visible = True
  679.              Text2.Visible = True
  680.              Text3.Visible = True
  681.              Text4.Visible = True
  682.              lblAnswer.Caption = "Present worth of annuity ($)"
  683.     End Select
  684. End Sub
  685. Private Sub cmdClear_click()
  686.     ClearAll
  687.     cboRef.Text = cboRef.List(cboRef.ListIndex)
  688.     Text1.SetFocus
  689. End Sub
  690. Private Sub cmdAnswer_Click()
  691.     On Error GoTo errHandler
  692.     If Text1.Visible Then
  693.          If Val(Format(Text1.Text)) = 0 Then
  694.              MsgBox "Cannot have zero value"
  695.              Text1.SetFocus
  696.              Exit Sub
  697.          Else
  698.              If IsAmountEntry(Text1.Text) = False Then
  699.                    MsgBox "Invalid entry"
  700.                    Text1.SetFocus
  701.                    Exit Sub
  702.              End If
  703.          End If
  704.     End If
  705.     If Text2.Visible Then
  706.          If Val(Format(Text2.Text)) = 0 Then
  707.              MsgBox "Cannot have zero value"
  708.              Text2.SetFocus
  709.              Exit Sub
  710.          Else
  711.              If IsAmountEntry(Text2.Text) = False Then
  712.                    MsgBox "Invalid entry"
  713.                    Text2.SetFocus
  714.                    Exit Sub
  715.              End If
  716.          End If
  717.     End If
  718.     If Text3.Visible Then
  719.          If Val(Format(Text3.Text)) = 0 Then
  720.              MsgBox "Cannot have zero value"
  721.              Text3.SetFocus
  722.              Exit Sub
  723.          Else
  724.              If IsAmountEntry(Text3.Text) = False Then
  725.                    MsgBox "Invalid entry"
  726.                    Text3.SetFocus
  727.                    Exit Sub
  728.              End If
  729.          End If
  730.     End If
  731.     If Text4.Visible Then
  732.          If Val(Format(Text4.Text)) = 0 Then
  733.              MsgBox "Cannot have zero value"
  734.              Text4.SetFocus
  735.              Exit Sub
  736.          Else
  737.              If IsAmountEntry(Text4.Text) = False Then
  738.                    MsgBox "Invalid entry"
  739.                    Text4.SetFocus
  740.                    Exit Sub
  741.              End If
  742.          End If
  743.     End If
  744.      
  745.     Dim i, a, p, r, q, y, n, f, t, ct, X
  746.     Select Case cboRef.ListIndex
  747.         Case 0
  748.             p = Val(Text1.Text)
  749.             f = Val(Text2.Text)
  750.             X = (f * 12 / p) * 100
  751.             If X < 0 Then
  752.                 MsgBox "Invalid/illogical input data"
  753.                 Exit Sub
  754.             End If
  755.             txtAnswer.Text = Format(X, "##,##0.00")
  756.         Case 1
  757.             p = Val(Text1.Text)              ' Price of paper
  758.             n = Val(Text2.Text)              ' No. of days
  759.             a = Val(Text3.Text)              ' Maturity value
  760.             X = ((a - p) / p * (365 / n)) * 100
  761.             If X < 0 Then
  762.                 MsgBox "Invalid/illogical input data"
  763.                 Exit Sub
  764.             End If
  765.             lblAnswerNote.Caption = "(If basing on 365 days, exact interest rate is " & _
  766.                     Format(X, "##,##0.00") & "% p.a.)"
  767.             lblAnswerNote.Visible = True
  768.             
  769.             X = ((a - p) / p * (360 / n)) * 100
  770.             txtAnswer.Text = Format(X, "##,##0.00")
  771.         Case 2
  772.             a = Val(Text1.Text)
  773.             n = Val(Text2.Text) / 100
  774.             r = Val(Text3.Text)
  775.             X = a / (1 + (r * n / 365))
  776.             If X < 0 Then
  777.                 MsgBox "Invalid/illogical input data"
  778.                 Exit Sub
  779.             End If
  780.             txtAnswer.Text = Format(X, "##,##0")
  781.         Case 3
  782.             p = Val(Text1.Text)             ' Cash price less downpayment
  783.             n = Val(Text2.Text)             ' Total No. of pmts
  784.             a = Val(Text3.Text)             ' Amount of each pmt
  785.             r = ((2 * 12 * ((a * n) - p)) / (p * (n + 1))) * 100
  786.             
  787.               '----------------------------------------------------
  788.                ' Traditionally the rate quoted would have been as above
  789.                ' basing on the generally accepted conventional method of
  790.                ' computation.
  791.               '----------------------------------------------------
  792.                ' But now we can test and refine it
  793.               '----------------------------------------------------
  794.             testFlag1 = False
  795.             testFlag2 = False
  796.             
  797.             r = r / 12 / 100
  798.             
  799.             Screen.MousePointer = vbHourglass
  800. Refine_Case3:
  801.             q = p
  802.             For i = 1 To n                   ' Loop through total No. of pmts
  803.                 X = q * (1 + r) - a
  804.                 q = X
  805.             Next i
  806.             If X > 0 Then
  807.                  If testFlag2 = False Then
  808.                      If (r - 0.00001) > 0 Then
  809.                           testFlag1 = True
  810.                           r = r - 0.00001
  811.                           GoTo Refine_Case3
  812.                      End If
  813.                  End If
  814.             ElseIf X < 0 Then
  815.                 If testFlag1 = False Then
  816.                     testFlag2 = True
  817.                     r = r + 0.00001
  818.                     GoTo Refine_Case3
  819.                 End If
  820.             End If
  821.             
  822.               ' Convert r back to "per year"
  823.             X = r * 12 * 100
  824.             Screen.MousePointer = vbDefault
  825.                
  826.             If X < 0 Then
  827.                 MsgBox "Invalid/illogical input data"
  828.                 Exit Sub
  829.             ElseIf X > 99 Then
  830.                 MsgBox "Invalid/illogical input data"
  831.                 Exit Sub
  832.             End If
  833.             txtAnswer.Text = Format(X, "##,##0.00")
  834.             
  835.         Case 4
  836.             p = Val(Text1.Text)             ' Mortgage amount
  837.             n = Val(Text2.Text)             ' Total No. of pmts
  838.             r = Val(Text3.Text)             ' Interest rate
  839.               '----------------------------------------------------
  840.               ' Conventional method uses 2 below; this is not an absolute.
  841.               ' The figure of "12" is used below as there are 12 payments
  842.               ' in a year.
  843.               '----------------------------------------------------
  844.             r = r / 100
  845.             X = (((p * (n + 1) * r / (2 * 12)) + p)) / n
  846.             
  847.               '----------------------------------
  848.               ' The above conventional method had been used in the past when
  849.               ' computer was not commonly available, nowadays we should apply
  850.               ' a better approach to arrive at an more accurate answer.
  851.               '----------------------------------
  852.               ' The amount of payment should be such that after discharging
  853.               ' last payment there is zero balance. Test it and refine it if
  854.               ' required
  855.               '----------------------------------
  856.             testFlag1 = False
  857.             testFlag2 = False
  858.             
  859.             r = r / 12
  860.             
  861.             Screen.MousePointer = vbHourglass
  862. Refine_Case4:
  863.             q = p
  864.             For i = 1 To n                   ' Loop through total No. of pmts
  865.                 t = q * (1 + r) - X
  866.                 q = t
  867.             Next i
  868.             If t > 0 Then
  869.                 If testFlag2 = False Then
  870.                       testFlag1 = True
  871.                       X = X + 1
  872.                       GoTo Refine_Case4
  873.                 End If
  874.             ElseIf t < 0 Then
  875.                 If testFlag1 = False Then
  876.                      If (X - 1) > 0 Then
  877.                           testFlag2 = True
  878.                           X = X - 1
  879.                           GoTo Refine_Case4
  880.                      End If
  881.                 End If
  882.             End If
  883.             
  884.             Screen.MousePointer = vbDefault
  885.             If X < 0 Then
  886.                 MsgBox "Invalid/illogical input data"
  887.                 Exit Sub
  888.             End If
  889.             txtAnswer.Text = Format(X, "##,##0")
  890.             
  891.         Case 5
  892.             p = Val(Text1.Text)             ' Mortgage amount
  893.             n = Val(Text2.Text)             ' Total No. of pmts
  894.             a = Val(Text3.Text)             ' Each pmt
  895.             t = a * n - p
  896.             r = (2 * 12 * t) / (p * (n + 1))
  897.             testFlag1 = False
  898.             testFlag2 = False
  899.             r = r / 12
  900.             
  901.             Screen.MousePointer = vbHourglass
  902. Refine_Case5:
  903.             q = p
  904.             For i = 1 To n                   ' Loop through total No. of pmts
  905.                 X = q * (1 + r) - a
  906.                 q = X
  907.             Next i
  908.             If X > 0 Then
  909.                  If testFlag2 = False Then
  910.                      If (r - 0.00001) > 0 Then
  911.                           testFlag1 = True
  912.                           r = r - 0.00001
  913.                           GoTo Refine_Case5
  914.                      End If
  915.                  End If
  916.             ElseIf X < 0 Then
  917.                 If testFlag1 = False Then
  918.                     testFlag2 = True
  919.                     r = r + 0.00001
  920.                     GoTo Refine_Case5
  921.                 End If
  922.             End If
  923.             
  924.               ' Convert r back to "per year", and "%",  for display
  925.             X = (r * 12) * 100
  926.             Screen.MousePointer = vbDefault
  927.             If X < 0 Then
  928.                 MsgBox "Invalid/illogical input data"
  929.                 Exit Sub
  930.             End If
  931.             txtAnswer.Text = Format(X, "##,##0.00")
  932.             
  933.         Case 6
  934.             p = Val(Text1.Text)             ' Mortgage amount
  935.             n = Val(Text2.Text)             ' Total No. of pmts
  936.             a = Val(Text3.Text)             ' Each pmt
  937.             f = Val(Text4.Text)             ' To exercise option after No. of pmts
  938.             If n < 49 Then
  939.                  If f <> n Then
  940.                       MsgBox "No option possible in this case"
  941.                       Exit Sub
  942.                  End If
  943.             End If
  944.             If f < 24 Then
  945.                  MsgBox "Can exercise the option after at least 24 pmts"
  946.                  Text4.SetFocus
  947.                  Exit Sub
  948.             ElseIf f > (n - 24) Then
  949.                  MsgBox "Cannot exercise the option during last 24 pmts"
  950.                  Text4.SetFocus
  951.                  Exit Sub
  952.             End If
  953.             t = a * n - p                                ' Total interest amount
  954.             
  955.               ' Calculate interest rate, preliminarily
  956.             r = (2 * 12 * t) / (p * (n + 1))               ' No "* 100"
  957.               ' Convert to "per month"
  958.             r = r / 12                                     ' hence no "/ 100"
  959.             
  960.             If r < 0 Then
  961.                 MsgBox "Invalid/illogical input data"
  962.                 Exit Sub
  963.             End If
  964.             testFlag1 = False
  965.             testFlag2 = False
  966.             Screen.MousePointer = vbHourglass
  967. Refine_Case6:
  968.             q = p
  969.             For i = 1 To n
  970.                 X = q * (1 + r) - a
  971.                 q = X
  972.             Next i
  973.             If X > 0 Then
  974.                  If testFlag2 = False Then
  975.                           ' Try to reduce interest rate
  976.                      If (r - 0.00001) > 0 Then
  977.                           testFlag1 = True
  978.                           r = r - 0.00001
  979.                           GoTo Refine_Case6
  980.                      End If
  981.                  End If
  982.             ElseIf X < 0 Then
  983.                 If testFlag1 = False Then
  984.                     testFlag2 = True
  985.                       ' Try to increase interest rate
  986.                     r = r + 0.00001
  987.                     GoTo Refine_Case6
  988.                 End If
  989.             End If
  990.             
  991.               '----------------------------------
  992.               ' Continue after above testing
  993.               '----------------------------------
  994.             t = 0
  995.             ct = 0
  996.             q = p
  997.             For i = 1 To f
  998.                 t = q * r                            ' Interest
  999.                 ct = ct + t                          ' Cumulated interest
  1000.                 X = q * (1 + r) - a
  1001.                 q = X
  1002.             Next i
  1003.             
  1004.             lblAnswerNote.Caption = "A: Of total payment of $" & Format(a * f, "##,##0") & _
  1005.                 " paid so far: $" & Format(ct, "###,###,##0") & " is interest portion," & _
  1006.                 "  $" & Format(a * f - ct, "###,###,##0") & " is principal portion."
  1007.             lblAnswerNote.Visible = True
  1008.                ' We better not to use X directly, as there is likely to be an
  1009.                ' accumulated rounding diff which may cause it to differ from
  1010.                ' the figure of p-(a*f-ct)
  1011.             txtAnswer.Text = Format(p - (a * f - ct), "##,##0")
  1012.             
  1013.             Screen.MousePointer = vbDefault
  1014.             
  1015.         Case 7
  1016.             a = Val(Text1.Text)
  1017.             y = Val(Text2.Text)
  1018.             r = Val(Text3.Text)
  1019.             q = Val(Text4.Text)
  1020.             r = r / 100
  1021.             X = a / (((1 + r / q)) ^ (y * q))
  1022.             If X < 0 Then
  1023.                 MsgBox "Invalid/illogical input data"
  1024.                 Exit Sub
  1025.             End If
  1026.             txtAnswer.Text = Format(X, "##,##0")
  1027.         Case 8
  1028.             f = Val(Text1.Text)
  1029.             y = Val(Text2.Text)
  1030.             r = Val(Text3.Text)
  1031.             q = Val(Text4.Text)
  1032.             r = r / 100
  1033.             X = (f * ((1 + r / q) ^ (y * q) - 1)) _
  1034.                       / (((1 + (r / q)) ^ q) - 1)
  1035.             If X < 0 Then
  1036.                 MsgBox "Invalid/illogical input data"
  1037.                 Exit Sub
  1038.             End If
  1039.             txtAnswer.Text = Format(X, "##,##0")
  1040.             
  1041.         Case 9
  1042.             f = Val(Text1.Text)               ' Yearly draw
  1043.             y = Val(Text2.Text)               ' No. of years
  1044.             r = Val(Text3.Text)               ' Interest rate
  1045.             r = r / 100
  1046.             X = f * ((1 - (1 / ((1 + r) ^ y))) / r)
  1047.             If X < 0 Then
  1048.                 MsgBox "Invalid/illogical input data"
  1049.                 Exit Sub
  1050.             End If
  1051.             txtAnswer.Text = Format(X, "##,##0")
  1052.             
  1053.         Case 10
  1054.             f = Val(Text1.Text)               ' Yearly draw
  1055.             q = Val(Text2.Text)               ' % increment each year
  1056.             y = Val(Text3.Text)               ' No. of years
  1057.             r = Val(Text4.Text)               ' Interest rate
  1058.               ' Same as above
  1059.             r = r / 100
  1060.             X = f * ((1 - (1 / ((1 + r) ^ y))) / r)
  1061.               ' Above plus increments in years after the first year
  1062.             X = X + (X / 15) * (1 + q / 100) ^ (y - 1)
  1063.             If X < 0 Then
  1064.                 MsgBox "Invalid/illogical input data"
  1065.                 Exit Sub
  1066.             End If
  1067.             txtAnswer.Text = Format(X, "##,##0")
  1068.     End Select
  1069.     lblAnswer.Visible = True
  1070.     txtAnswer.Visible = True
  1071.     Exit Sub
  1072. errHandler:
  1073.     MsgBox "Error occurred, cannot yield a valid answer"
  1074. End Sub
  1075. Sub FilterAmountKey(mInKey)
  1076.     If mInKey < Asc("0") Or mInKey > Asc("9") Then
  1077.           If mInKey <> 32 And mInKey <> 8 Then     'Allow Space & Backspace
  1078.                 If mInKey <> Asc(".") Then         ' Allow decimal
  1079.                     mInKey = 0            ' Cancel the typed in character
  1080.                 End If
  1081.           End If
  1082.     End If
  1083. End Sub
  1084. Function IsAmountEntry(txt As String) As Boolean
  1085.     Dim ch As String
  1086.     Dim i As Integer, j As Integer
  1087.     IsAmountEntry = False
  1088.     If Len(LTrim(RTrim(txt))) = 0 Then
  1089.         Exit Function
  1090.     End If
  1091.     j = 0
  1092.     For i = 1 To Len(txt)
  1093.         ch = Mid$(txt, i, 1)
  1094.         If ch < "0" Or ch > "9" Then
  1095.             If ch <> "." Then
  1096.                 Exit Function
  1097.             Else
  1098.                 j = j + 1
  1099.             End If
  1100.         End If
  1101.     Next i
  1102.     If j > 1 Then
  1103.         Exit Function
  1104.     End If
  1105.     IsAmountEntry = True
  1106. End Function
  1107.